import {Actions,Store,Mutations} from "../enums/Store";

export const state = () => ({
    [Store.Skin]:{},
    [Store.User]:process.browser?localStorage.getItem('user')||{}:{},
    [Store.Recommend]:{},
    [Store.Latest]:{},
    [Store.LatestDetail]:{},
	[Store.IsModal]:{},
	[Store.CurrentSongs]:{}
})

export const mutations={
  [Mutations.SetSkin](state,data){
      state[ Store.Skin ] = data
    },

  [Mutations.SetUser](state,data){
    localStorage.setItem('user',data)
    state[ Store.User ] = data
  },

  [Mutations.SetRecommend](state,data){
    state[ Store.Recommend ] = data
  },

  [Mutations.SetLatest](state,data){
    state[ Store.Latest ] = data
  },

  [Mutations.SetLatestDetail](state,data){
    state[ Store.LatestDetail ] = data
  },
  
  [Mutations.SetIsModal](state,data){
    state[ Store.IsModal ] = data
  },
  
  [Mutations.SetCurrentSongs](state,data){
    state[ Store.CurrentSongs ] = data
  },
}

export const actions={
  async nuxtServerInit({ commit },{app}) {
    commit(Mutations.SetSkin,0)
	commit(Mutations.SetIsModal,false)
  },

  async [Actions.GetSkin]({commit},params) {
        commit(Mutations.SetSkin,params)
   },
   
  async [Actions.GetIsModal]({commit},val) {
        commit(Mutations.SetIsModal,val)
   },
   
  async [Actions.GetCurrentSongs]({commit},songs) {
         commit(Mutations.SetCurrentSongs,songs)
   },
   
  async [Actions.GetUser]({commit},user) {
      commit(Mutations.SetUser,user)
  },

  async [ Actions.GetRecommend ]({ commit }) {
    commit(Mutations.SetRecommend, await this.$axios.$get('/kugou/recommend?json=true'))
  },

  async [ Actions.GetLatest ]({ commit }) {
    commit(Mutations.SetLatest, await this.$axios.$get('/kugou/latest?json=true'))
  },

  async [ Actions.GetLatestDetail ]({ commit },rankid) {
    commit(Mutations.SetLatestDetail, await this.$axios.$get(`/kugou/detail?json=true&rankid=${rankid}`))
  }


}
